<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qqmlnetworkaccessmanagerfactory.cpp -->
  <title>QQmlNetworkAccessManagerFactory  类 | Qt QML 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtqml-index.html">Qt QML</a></td><td ><a href="qtqml-module.html">C++ 类</a></td><td >QQmlNetworkAccessManagerFactory</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtqml-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">目录</a></h3>
<ul>
<li class="level1"><a href="#public-functions">公用函数</a></li>
<li class="level1"><a href="#details">详细信息</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QQmlNetworkAccessManagerFactory 类</h1>
<!-- $$$QQmlNetworkAccessManagerFactory-brief -->
<p><a href="qqmlnetworkaccessmanagerfactory.html">QQmlNetworkAccessManagerFactory</a>类为QML引擎创建QNetworkAccessManager实例。 <a href="#details">更多...</a></p>
<!-- @@@QQmlNetworkAccessManagerFactory -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> 头文件：</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QQmlNetworkAccessManagerFactory&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += qml</td></tr><tr><td class="memItemLeft rightAlign topAlign"> 
	<span lang="zh-cn">从：</span></td><td class="memItemRight bottomAlign">  Qt 5.0</td></tr></table></div><ul>
<li><a href="qqmlnetworkaccessmanagerfactory-members.html"></a></li>
</ul>
<a name="public-functions"></a>
<h2 id="public-functions">公用函数</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> virtual </td><td class="memItemRight bottomAlign"><b><a href="qqmlnetworkaccessmanagerfactory.html#dtor.QQmlNetworkAccessManagerFactory">~QQmlNetworkAccessManagerFactory</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual QNetworkAccessManager *</td><td class="memItemRight bottomAlign"><b><a href="qqmlnetworkaccessmanagerfactory.html#create">create</a></b>(QObject *<i>parent</i>) = 0</td></tr>
</table></div>
<a name="details"></a>
<!-- $$$QQmlNetworkAccessManagerFactory-description -->
<div class="descr">
<h2 id="details">详细信息</h2>
<p><a href="qqmlnetworkaccessmanagerfactory.html">QQmlNetworkAccessManagerFactory</a>类为QML引擎创建QNetworkAccessManager实例。</p>
<p>
QML引擎使用QNetworkAccessManager进行所有网络访问。通过实现工厂，可以为QML引擎提供具有专门缓存、代理和cookie支持的自定义QNetworkAccessManager实例。</p>
<p>要实现一个工厂，子类<a href="qqmlnetworkaccessmanagerfactory.html">QQmlNetworkAccessManagerFactory</a>并实现虚拟<a href="qqmlnetworkaccessmanagerfactory.html#create">create</a>()方法，然后使用<a href="qqmlengine.html#setNetworkAccessManagerFactory">QQmlEngine::setNetworkAccessManagerFactory</a>()将它分配给相关的QML引擎。</p>
<p>注意，QML引擎可以从多个线程创建QNetworkAccessManager实例。因此，<a href="qqmlnetworkaccessmanagerfactory.html#create">create</a>()方法的实现必须是<a href="../qtcore/qrandomgenerator.html#reentrancy-and-thread-safety">可重入</a>的。此外，如果从<a href="qqmlnetworkaccessmanagerfactory.html#create">create</a>()返回的对象的信号连接到可能在不同线程中创建的对象的槽，开发人员应该小心:</p>
<ul>
<li>
QML引擎在内部处理所有请求，并清理它创建的任何QNetworkReply对象。在另一个线程中接收QNetworkAccessManager::finished()信号可能不会向接收方提供一个有效的应答对象，如果该对象已经被删除。</li>
<li>提供给QNetworkAccessManager::authenticationRequired()的身份验证细节必须立即提供，因此此信号不能作为 <a href="../qtcore/qt.html#ConnectionType-enum">Qt::QueuedConnection</a>连接(或作为来自另一个线程的默认<a href="../qtcore/qt.html#ConnectionType-enum">Qt::AutoConnection</a>)。</li>
</ul>
<p>有关信号和线程的更多信息，请参见<a href="../qtdoc/threads-qobject.html">线程和<span lang="zh-cn">QO</span>bject</a>以及<a href="../qtdoc/threads-qobject.html#signals-and-slots-across-threads">跨线程的信号和槽</a>。</p>
</div>
<p><b>请参考 </b><a href="qtqml-networkaccessmanagerfactory-example.html">
<span lang="zh-cn">网络访问管理其工厂示例</span></a><span lang="zh-cn">。</span></p>
<!-- @@@QQmlNetworkAccessManagerFactory -->
<div class="func">
<h2>成员函数的文档</h2>
<!-- $$$~QQmlNetworkAccessManagerFactory[overload1]$$$~QQmlNetworkAccessManagerFactory -->
<h3 class="fn" id="dtor.QQmlNetworkAccessManagerFactory"><a name="dtor.QQmlNetworkAccessManagerFactory"></a><code>[virtual] </code>QQmlNetworkAccessManagerFactory::<span class="name">~QQmlNetworkAccessManagerFactory</span>()</h3>
<p>破坏了工厂。默认实现什么也不做。</p>
<!-- @@@~QQmlNetworkAccessManagerFactory -->
<!-- $$$create[overload1]$$$createQObject* -->
<h3 class="fn" id="create"><a name="create"></a><code>[pure virtual] </code><span class="type">QNetworkAccessManager</span> *QQmlNetworkAccessManagerFactory::<span class="name">create</span>(<span class="type"><a href="../qtcore/qobject.html">QObject</a></span> *<i>parent</i>)</h3>
<p>创建并返回具有指定父节点的网络访问管理器。每次调用该方法时，必须返回一个新的QNetworkAccessManager实例。</p>
<p>注意：这个方法可能会被多个线程调用，所以要确保这个方法的实现是可重入的。</p>
<!-- @@@create -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
